import random


def mazeBuild(length, width, percent):  # 随机生成构建地图，按percent比例生成障碍物
    global start_Point, end_Point
    obstacle = []  # 存放障碍物的列表
    obstacle_num = int(length * width * percent)
    for i in range(obstacle_num + 2):
        if i < obstacle_num:
            x = random.randint(0, length - 1)
            y = random.randint(0, width - 1)
            location = (x, y)
            obstacle.append(location)
        elif i == obstacle_num:
            x = random.randint(1, length - 3)
            y = random.randint(1, width - 3)
            start_Point = (x, y)
        elif i == obstacle_num + 1:
            x = random.randint(1, length - 3)
            y = random.randint(1, width - 3)
            end_Point = (x, y)

    for i in range(length):  # 生成外边框
        x_wall_u = (i, 0)
        obstacle.append(x_wall_u)
        x_wall_d = (i, width - 2)
        obstacle.append(x_wall_d)

    for i in range(width):  # 生成外边框
        y_wall_r = (0, i)
        obstacle.append(y_wall_r)
        y_wall_l = (length - 2, i)
        obstacle.append(y_wall_l)

    return obstacle, start_Point, end_Point
